package org.person.springcloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.person.springcloud.models.CommonResult;
import org.person.springcloud.models.Payment;
import org.springframework.web.bind.annotation.*;
import org.springframework.web. client.RestTemplate;
import javax.annotation.Resource;

@RestController
@Slf4j
public class OrderController {

//    public static final String PAYMENT_URL = "http://localhost:8001";
    public static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVICE";

    @Resource
    private RestTemplate restTemplate;

    @PostMapping("/consumer/payment")
    public CommonResult<Payment> save(@RequestBody Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL + "/payment", payment, CommonResult.class);
    }

    @GetMapping("/consumer/payment/{id}")
    public CommonResult<Integer> save(@PathVariable("id") Long id) {
        return restTemplate.getForObject(PAYMENT_URL + "/payment/" + id, CommonResult.class);
    }

    @GetMapping("/consumer/sleuth")
    public String sleuth() {
        return restTemplate.getForObject(PAYMENT_URL + "/sleuth", String.class);
    }
}
